import { Controller, Get, Post, Body, Param, Put } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { KeyValueStore_Service } from './keyValueStore.service';
import { KeyValueStore_Create_Dto, KeyValueStore_Update_Dto } from './assets/keyValueStore.dto';
import { KeyValueStore } from './assets/keyValueStore.entity';
import { util_ApiResponse_Base } from '@/common/util/apiResponse';
import { IConstant_Enum_Type_KeyValueStore_Enum_TypeKey } from '@/common/constants/enum';
import { util_Index_ReturnContent } from '@/common/util/index';

@Controller('/adm/keyValueStore')
@ApiTags('keyValueStore 键值对')
export class KeyValueStore_Controller {
  constructor(private readonly keyValueStore_Service: KeyValueStore_Service) {}

  @Post('/add')
  @util_ApiResponse_Base({
    dataType: 'dataType_add',
    //apiKey: '/adm/keyValueStore/add Post',
  })
  async keyValueStore_Create(@Body() body: KeyValueStore_Create_Dto) {
    return util_Index_ReturnContent(await this.keyValueStore_Service.keyValueStore_Create(body));
  }

  @Get('/storeKey/:storeKey')
  @util_ApiResponse_Base({
    dataType: 'dataType_ell',
    summary: '根据键获取详情',
    //apiKey: '/adm/keyValueStore/storeKey/:storeKey Get',
  })
  async keyValueStore_FindOneByStoreKey(
    @Param('storeKey')
    storeKey: IConstant_Enum_Type_KeyValueStore_Enum_TypeKey,
  ) {
    return util_Index_ReturnContent<KeyValueStore>(
      await this.keyValueStore_Service.keyValueStore_FindOneByStoreKey(storeKey),
    );
  }

  @Put('/update')
  @util_ApiResponse_Base({
    dataType: 'dataType_update',
    //apiKey: '/adm/keyValueStore/update Put',
  })
  async keyValueStore_Update(@Body() body: KeyValueStore_Update_Dto) {
    return util_Index_ReturnContent(await this.keyValueStore_Service.keyValueStore_Update(body));
  }
}
